const logger = require('log4js').getLogger()

module.exports = (req, res) => {
  require('../util/service').handlePost(req, res, (reqObj, resolve) => {
    const mongoMng = require('../mng/mongoMng')
    if (!mongoMng.db) {
      logger.error('[' + __filename + ':' + __line + ']', '未连接mongo')
      resolve({
        result: -1,
        msg: '系统错误'
      })
      return
    }
    if (!reqObj.returnWay) {
      resolve({
        result: -1,
        msg: '缺少returnWay'
      })
      return
    }
    mongoMng.db.collection('user').update({
      phone: req.session.customer.phone
    }, {
      $set: {
        returnWay: reqObj.returnWay
      }
    }, (err, result) => {
      if (err) {
        logger.error('[' + __filename + ':' + __line + ']', err)
        resolve({
          result: -1,
          msg: '系统错误'
        })
        return
      }
      resolve({
        result: 1
      })
    })
  })
}